﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Mail;
using System.Web.Security;
using System.Security.Cryptography;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Globalization;

/// <summary>
/// Summary description for common
/// </summary>
public class comm
{
    public comm()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public static string convertMoney(int money,string type)
    {
        string kq = "";
        kq = String.Format("{0:0,0}", money)+type;
        return kq;
    }
    public static string rsStatus(int status)
    {
        string kq = "Không Dùng";
        if (status == 1)
        {
            kq = "Dùng";
        }
        else
        {
            kq = "Không Dùng";
        }
        return kq;
    }
    public static string getSubString(string str, int len)
    {
        string kq = "";
        if (str.Length > len)
        {
            str = str.Substring(0, len);
            string[] strNice = str.Split(' ');
            if (str.EndsWith(" ") == true)
            {
                kq = str.Substring(0, len).Trim() + "...";
            }
            else
            {
                for (int i = 0; i < (strNice.Length - 1); i++)
                {
                    kq += strNice[i] + " ";
                }
                kq = kq.Trim() + "...";
            }
        }
        else
        {
            kq = str;
        }
        return kq;
    }
    public static string getSubStringNice(string str, int len)
    {
        //chu dep
        string kq = "";
        if (str.Length > len)
        {
            str = str.Substring(0, len);
            string[] strNice = str.Split(' ');
            if (str.EndsWith(" ") == true)
            {
                kq = str.Substring(0, len).Trim() + "...";
            }
            else
            {
                for (int i = 0; i < (strNice.Length - 1); i++)
                {
                    kq += strNice[i] + " ";
                }
                kq = kq.Trim() + "...";
            }
        }
        else
        {
            kq = str;
        }
        return kq;
    }
    public static int getRowCount(DataTable dt)
    {
        try
        {
            if (dt.Rows.Count > 0)
            {
                return int.Parse(dt.Rows[0]["TotalRecord"].ToString());
            }
            else return 0;
        }
        catch
        {
            return 0;
        }
    }
    public static int getPage()
    {
        try
        {
            string pagevalue = (System.Web.HttpContext.Current.Request["page"] == null) ? "1" : System.Web.HttpContext.Current.Request["page"].ToString().Trim();
            int page = 0;
            if (!(int.TryParse(pagevalue, out page)))
            {
                System.Web.HttpContext.Current.Response.Redirect("/");
                return 0;
            }
            else
            {
                page = page - 1;
            }
            return page;
        }
        catch
        {
            return 0;
        }
    }
    public static string BuyItemCommand = ConfigurationManager.AppSettings["BuyItemCommand"] == null ? "AB" : ConfigurationManager.AppSettings["BuyItemCommand"].ToString();
    public static DateTime getStrTimeToDateTime(string timeYYYYMMDDHHMMSS)
    {
        if (timeYYYYMMDDHHMMSS.Length > 8) return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMddHHmmss", null);
        return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMdd", null);
    }
    public static string getStrTimeToDateTimeView(string timeYYYYMMDDHHMMSS)
    {
        if (timeYYYYMMDDHHMMSS.Length > 8) return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMddHHmmss", null).ToString("dd/MM/yyyy HH:mm:ss");
        return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMdd", null).ToString("dd/MM/yyyy");
    }

    public static string getStandardStrTimeToDateTimeView(string time)
    {
        try
        {
            if (time != "" && time != null) return DateTime.Parse(time).ToString("dd/MM/yyyy HH:mm:ss");
        }
        catch { }
        return "";
    }

    public static string getDatetimeToStrDateTimeView(string timeYYYYMMDDHHMMSS)
    {
        if (timeYYYYMMDDHHMMSS.Length > 8) return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMddHHmmss", null).ToString("dd/MM/yyyy HH:mm:ss");
        return DateTime.ParseExact(timeYYYYMMDDHHMMSS, "yyyyMMdd", null).ToString("dd/MM/yyyy");
    }
    /// <summary>
    /// DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
    //String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
    //String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
    //String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
    //String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
    //String.Format("{0:m mm}",          dt);  // "5 05"            minute
    //String.Format("{0:s ss}",          dt);  // "7 07"            second
    //String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
    //String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
    //String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
    //String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone
    //String.Format("{0:t}", dt);  // "4:05 PM"                         ShortTime
    //String.Format("{0:d}", dt);  // "3/9/2008"                        ShortDate
    //String.Format("{0:T}", dt);  // "4:05:07 PM"                      LongTime
    //String.Format("{0:D}", dt);  // "Sunday, March 09, 2008"          LongDate
    //String.Format("{0:f}", dt);  // "Sunday, March 09, 2008 4:05 PM"  LongDate+ShortTime
    //String.Format("{0:F}", dt);  // "Sunday, March 09, 2008 4:05:07 PM" FullDateTime
    //String.Format("{0:g}", dt);  // "3/9/2008 4:05 PM"                ShortDate+ShortTime
    //String.Format("{0:G}", dt);  // "3/9/2008 4:05:07 PM"             ShortDate+LongTime
    //String.Format("{0:m}", dt);  // "March 09"                        MonthDay
    //String.Format("{0:y}", dt);  // "March, 2008"                     YearMonth
    //String.Format("{0:r}", dt);  // "Sun, 09 Mar 2008 16:05:07 GMT"   RFC1123
    //String.Format("{0:s}", dt);  // "2008-03-09T16:05:07"             SortableDateTime
    //String.Format("{0:u}", dt);  // "2008-03-09 16:05:07Z"            UniversalSortableDateTime


    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static string getVietnameseDateTimeString(DateTime dt)
    {
        string strDate = String.Format("{0:dddd, dd MMMM, yyyy hh:mm}", dt);

        strDate = getVietnameseWeek(strDate);
        strDate = getVietnameseMonth(strDate);
        strDate = getVietnameseSessions(strDate);
        return strDate;

    }

    public static string getVietnameseWeek(string strDate)
    {
        strDate = strDate.Replace("Sunday", "Chủ nhật");
        strDate = strDate.Replace("Monday", "Thứ hai");
        strDate = strDate.Replace("Tuesday", "Thứ ba");
        strDate = strDate.Replace("Wenesday", "Thứ tư");
        strDate = strDate.Replace("Thursday", "Thứ năm");
        strDate = strDate.Replace("Friday", "Thứ sáu");
        strDate = strDate.Replace("Saturday", "Thứ bảy");
        return strDate;
    }
    public static string getVietnameseMonth(string strDate)
    {
        strDate = strDate.Replace("January", "Tháng 1");
        strDate = strDate.Replace("February", "Tháng 2");
        strDate = strDate.Replace("March", "Tháng 3");
        strDate = strDate.Replace("April", "Tháng 4");
        strDate = strDate.Replace("May", "Tháng 5");
        strDate = strDate.Replace("June", "Tháng 6");
        strDate = strDate.Replace("July", "Tháng 7");
        strDate = strDate.Replace("August", "Tháng 8");
        strDate = strDate.Replace("September", "Tháng 9");
        strDate = strDate.Replace("October", "Tháng 10");
        strDate = strDate.Replace("November", "Tháng 11");
        strDate = strDate.Replace("December", "Tháng 12");

        return strDate;

    }
    public static string getVietnameseSessions(string strDate)
    {
        strDate = strDate.Replace("PM", "chiều");
        strDate = strDate.Replace("AM", "sáng");
        return strDate;
    }

    public static string SendMail(string SenderName, string SenderEmail, string RecieverEmail, string MailTitle, string MailContent)
    {
        try
        {
            MailMessage mail = new MailMessage();

            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.BodyFormat = MailFormat.Html;

            mail.To = RecieverEmail;

            mail.From = SenderEmail;

            mail.Subject = MailTitle;

            mail.Body = MailContent;

            SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SMTP"];

            SmtpMail.Send(mail);
            return "0";
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
    public static string SendMail(string SenderName, string SenderEmail, string RecieverEmail, string MailTitle, string MailContent, string sSmtpServer)
    {
        try
        {
            MailMessage mail = new MailMessage();

            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.BodyFormat = MailFormat.Html;

            mail.To = RecieverEmail;

            mail.From = SenderEmail;

            mail.Subject = MailTitle;

            mail.Body = MailContent;

            SmtpMail.SmtpServer = sSmtpServer;

            SmtpMail.Send(mail);
            return "0";
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
    public static string getRandomNumber(int ilenght)
    {
        Random rdn = new Random();
        int MaxNumber;
        MaxNumber = 1;
        for (int i = 1; i <= ilenght; i++)
        {
            MaxNumber = MaxNumber * 10;
        }
        String rdnString = (rdn.Next(MaxNumber)).ToString();
        while (rdnString.Length < ilenght)
        {
            rdnString = "0" + rdnString;
        }
        return rdnString;

    }
    public static string to_sqlnumber(string value)
    {
        return to_sql(value, "number");
    }
    public static string to_sqldate(string value)
    {
        return to_sql(value, "date");
    }
    public static string to_sqltext(string value)
    {
        return to_sql(value, "text");
    }
    public static string to_sqltextforlike(string value)
    {
        if (string.IsNullOrEmpty(value)) return "";
        return value.Replace("'", "''");
    }
    public static string to_sql(string value, string datatype)
    {
        if (string.IsNullOrEmpty(value))
        {
            return "NULL";
        }
        else
        {
            string temp;
            //temp = datatype;
            temp = (string)datatype.ToLower();
            if (temp.Equals("number"))
            {
                double Num;
                bool isNum;
                //isNum = false;
                //try{
                isNum = double.TryParse(value, out Num);
                //}
                //catch
                //{
                //    isNum = false;
                //}

                if (isNum)
                {
                    return Num.ToString();
                }
                else
                {
                    return "0";
                }
            }
            else if (temp.Equals("date"))
            {

                return "Convert([datetime], '" + value + "', 103)";

            }
            else //Luu tru va hien thi theo dinh dang dd/mm/yyyy - code 103
            {
                return "N'" + value.Replace("'", "''") + "'";
            }


        }
    }

    public static string to_paramurl(object value)
    {
        if (value != null) return value.ToString();
        else return "";
    }
    public static string to_htmlcode(string message)
    {
        if ((message.Equals(null)) || (message.Equals("")))
        {
            return null;
        }
        else
        {
            //return message.Replace("\n\r", "<br>");
            //return message.Replace("\n", "<br>");
            return message.Replace("\r", "<br>");
        }
    }
    public static string to_dataview(string message)
    {
        if ((message.Equals(null)) || (message.Equals("")))
        {
            return null;
        }
        else
        {
            string stemp = message;
            //stemp = stemp.Replace("<", "&lt;");
            //stemp = stemp.Replace(">", "&gt;");
            //stemp = stemp.Replace("\r", "<br>");
            stemp = stemp.Replace("\n", "<br>");
            return stemp;
        }
    }
    public static string to_textcode(string message)
    {
        if ((message.Equals(null)) || (message.Equals("")))
        {
            return null;
        }
        else
        {
            return message.Replace("<br>", "\r");
        }
    }
    public static string to_textview(string message)
    {
        if ((message.Equals(null)) || (message.Equals("")))
        {
            return null;
        }
        else
        {
            return message.Replace("<br>", "\n");
        }
    }

    public static string UnFormatNumber(string st, string stSpace)
    {
        if (st == null) return "";
        return st.Replace(stSpace, "");
    }

    public static string UnFormatNumber(string st)
    {
        return UnFormatNumber(st, ",");
    }

    public static string FormatNumber(string st)
    {
        return FormatNumber(st, 3, ",", 0);
    }
    public static string FormatNumber(string st, int slNhom, string stSpace, int lim)
    {

        if (st == null) return "";
        st = st.Trim();
        int i, sl, vt, cd;
        vt = 0;
        string tgst;
        cd = st.Length;
        if (cd <= slNhom) return st;
        sl = Convert.ToInt32((cd - 1) / slNhom);
        tgst = "";
        for (i = 1; i <= sl; i++)
        {
            vt = cd - slNhom * i;
            if (tgst != "") tgst = stSpace + tgst;
            tgst = st.Substring(vt, slNhom) + tgst;
            if ((lim > 0) && (i == lim + 1))
            {
                tgst = st.Substring(0, vt) + tgst;
                return tgst;
            }
        }
        if (vt > 0)
        {
            if (tgst != "") tgst = stSpace + tgst;
            tgst = st.Substring(0, vt) + tgst;
        }
        return tgst;
    }

    public static string fnEncrypt(string password)
    {
        byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
        try
        {
            System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
            cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] hash = cryptHandler.ComputeHash(textBytes);
            string ret = "";
            foreach (byte a in hash)
            {
                if (a < 16)
                    ret += "0" + a.ToString("x");
                else
                    ret += a.ToString("x");
            }
            return ret;
        }
        catch
        {
            throw;
        }
    }

    // ------Het cac ham xy ly xau-------

    // ------Cac ham xu ly thoi gian-------

    public static string GetStrTime()
    {
        return GetStrTime("");
    }

    public static string GetStrTime(string format)
    {

        string sdatetime, sYear, sMonth, sDay, sHour, sMinute;
        sYear = DateTime.Now.Year.ToString();
        sMonth = DateTime.Now.Month.ToString();
        sDay = DateTime.Now.Day.ToString();
        sHour = DateTime.Now.Hour.ToString();
        sMinute = DateTime.Now.Minute.ToString();
        if (sMonth.Length < 2) sMonth = "0" + sMonth;
        if (sDay.Length < 2) sDay = "0" + sDay;
        if (sHour.Length < 2) sHour = "0" + sHour;
        if (sMinute.Length < 2) sDay = "0" + sMinute;


        switch (format)
        {
            case "yyyymmdd":
                sdatetime = sYear + "/" + sMonth + "/" + sDay;
                break;
            case "mmddyyyy":
                sdatetime = sMonth + "/" + sDay + "/" + sYear;
                break;
            case "ddmmyyyy":
                sdatetime = sDay + "/" + sMonth + "/" + sYear;
                break;
            case "yyyymmddhhmm":
                sdatetime = sYear + "/" + sMonth + "/" + sDay + " " + sHour + ":" + sMinute;
                break;
            default:
                sdatetime = sDay + "/" + sMonth + "/" + sYear;
                break;
        }

        return sdatetime;

    }
    public static string GetStrTime(DateTime dtRef, string format)
    {

        string sdatetime, sYear, sMonth, sDay, sHour, sMinute, sSecond;
        sYear = dtRef.Year.ToString();
        sMonth = dtRef.Month.ToString();
        sDay = dtRef.Day.ToString();
        sHour = dtRef.Hour.ToString();
        sMinute = dtRef.Minute.ToString();
        sSecond = dtRef.Second.ToString();
        if (sMonth.Length < 2) sMonth = "0" + sMonth;
        if (sDay.Length < 2) sDay = "0" + sDay;
        if (sHour.Length < 2) sHour = "0" + sHour;
        if (sMinute.Length < 2) sMinute = "0" + sMinute;
        if (sSecond.Length < 2) sSecond = "0" + sSecond;

        switch (format)
        {
            case "yyyymmdd":
                sdatetime = sYear + "/" + sMonth + "/" + sDay;
                break;
            case "mmddyyyy":
                sdatetime = sMonth + "/" + sDay + "/" + sYear;
                break;
            case "ddmmyyyy":
                sdatetime = sDay + "/" + sMonth + "/" + sYear;
                break;
            case "hhmmss":
                sdatetime = sHour + ":" + sMinute + ":" + sSecond;
                break;
            case "yyyymmddhhmm":
                sdatetime = sDay + "/" + sMonth + "/" + sYear + " " + sHour + ":" + sMinute + ":00";
                break;
            case "yyyymmddhhmmss":
                sdatetime = sDay + "/" + sMonth + "/" + sYear + " " + sHour + ":" + sMinute + ":" + sSecond;
                break;
            default:
                sdatetime = sDay + "/" + sMonth + "/" + sYear;
                break;
        }

        return sdatetime;
    }
    public static DateTime GetDateFromStrVN(string dt)
    {
        string sdatetime, sYear, sMonth, sDay, sHour, sMinute, sSecond;
        string[] arr1 = dt.Split(new string[] { " " }, StringSplitOptions.None);
        string[] arr2 = arr1[0].Split(new string[] { "/" }, StringSplitOptions.None);
        string[] arr3 = arr1[1].Split(new string[] { ":" }, StringSplitOptions.None);

        sYear = arr2[2];
        sMonth = arr2[1];
        sDay = arr2[0];

        sHour = arr3[0];
        sMinute = arr3[1];
        sSecond = arr3[2];

        return new DateTime(int.Parse(sYear), int.Parse(sMonth), int.Parse(sDay), int.Parse(sHour), int.Parse(sMinute), int.Parse(sSecond));
    }
    public static Dictionary<string, int> _dicMemberIdTel = new Dictionary<string, int>();

    public static string GetDateFromStrVN(string dt, int i)
    {
        string sdatetime, sYear, sMonth, sDay, sHour, sMinute;
        string[] arr1 = dt.Split(new string[] { " " }, StringSplitOptions.None);
        string[] arr2 = arr1[0].Split(new string[] { "/" }, StringSplitOptions.None);
        string[] arr3 = arr1[1].Split(new string[] { ":" }, StringSplitOptions.None);

        sYear = arr2[2];
        sMonth = arr2[1];
        sDay = arr2[0];

        sHour = arr3[0];
        sMinute = arr3[1];

        return sYear + "-" + sMonth + "-" + sDay + "-" + sHour + "-" + sMinute;
    }
    // ------Het Cac ham xu ly thoi gian-------
    public static int GetMemberIdByTel(string sTel)
    {
        if (sTel.StartsWith("+84")) sTel = sTel.Substring(3);

        if (_dicMemberIdTel.ContainsKey(sTel))
        {
            return _dicMemberIdTel[sTel];
        }
        string sSql = "select id from Members where tel like '%" + comm.to_sqltextforlike(sTel) + "'";
        DataTable dt = DBUtil.SelectTable(sSql);
        if (dt.Rows.Count > 0)
        {
            int val = int.Parse(dt.Rows[0][0].ToString());
            _dicMemberIdTel[sTel] = val;
            return val;
        }
        return -1;
    }
    // ------Het Cac ham xu ly thoi gian-------
    public static int GetMemberID()
    {
        //return 2;
        {
            if (HttpContext.Current.Session["MemberID"] == null)
                return -1;

            return Convert.ToInt32(HttpContext.Current.Session["MemberID"].ToString());
        }
    }
    // ------Het Cac ham xu ly thoi gian-------
    public static string GetMemberTel()
    {
        {
            if (HttpContext.Current.Session["tel"] == null)
                return "-1";

            return (HttpContext.Current.Session["tel"].ToString());
        }
    }
    public static string GetMemberTelToView()
    {
        return Util.getTelToView(GetMemberTel());
    }
    public static string GetMemberName()
    {

        {
            if (HttpContext.Current.Session["NickName"] == null)
                return "";

            return HttpContext.Current.Session["NickName"].ToString();
        }
    }
    public static string GetBussinessID()
    {
        {
            return "";
        }
    }


    public static int GetAdminID()
    {
        {
            if (HttpContext.Current.Session["AdminID"] == null)
                return -1;

            return Convert.ToInt32(HttpContext.Current.Session["AdminID"].ToString());
        }
    }

    public static string GetAdminName()
    {
        {
            if (HttpContext.Current.Session["AdminName"] == null)
                return "";

            return HttpContext.Current.Session["AdminName"].ToString();
        }

    }


    //--------End function Identity function---
    //-----------Ham truy cap du lieu------------
    public static string GetFielTextByID(string sfiled, string stable, int id)
    {
        string stsql;
        stsql = "SELECT " + sfiled + " as fText FROM " + sfiled + " WHERE ID=" + to_sql(id.ToString(), "number");
        DataTable dt;
        dt = DBUtil.SelectTable(stsql);
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0]["fText"].ToString();
        }
        return "";
    }
    //-----------Ham truy cap du lieu------------
    public static string GetFieldTextByText(string sfiled, string sfiledC, string stable, string sValue)
    {
        string stsql;
        stsql = "SELECT " + sfiled + " as fText FROM " + stable + " WHERE " + sfiledC + " =" + to_sql(sValue, "text");
        DataTable dt;
        dt = DBUtil.SelectTable(stsql);
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0]["fText"].ToString();
        }
        return "";
    }

    public static string GetVariantFielTextIn(string sfiled)
    {
        string stsql;
        stsql = "SELECT " + sfiled + " as fText FROM Webvariants";
        DataTable dt;
        dt = DBUtil.SelectTable(stsql);
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0]["fText"].ToString();
        }
        return "";
    }
    public static string GetVariantSizeWebContach()
    {
        return GetVariantFielTextIn("SizeWeb");
    }
    public static string GetVariantCSS()
    {
        return GetVariantFielTextIn("CSS");
    }
    public static string GetVariantInfo()
    {
        return GetVariantFielTextIn("Info");
    }
    public static string GetVariantContract()
    {
        return GetVariantFielTextIn("Contract");
    }
    public static string GetVariantMailContach()
    {
        return GetVariantFielTextIn("mailcontach");
    }
    public static int GetVariantPageSize()
    {
        return 9;
        try
        {
            return Convert.ToInt32(ConfigurationSettings.AppSettings["page_size"]);
            //if (GetVariantFielTextIn("pagesize") == "") return 20;
            //return Convert.ToInt32(GetVariantFielTextIn("pagesize"));
        }
        catch (Exception ex) { return 10; }
    }

    //-----------Het ham truy cap du lieu------------
    //KET THUC PHAN TA VIET CODE 
    public static DateTime Now
    {
        get
        {
            DateTime d = DateTime.Now;
            return d;
        }
    }
    // media

    // media
    //player to cut files for admin
    public static string getLayer(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;
        string width = "100%";// "600px";
        height = "100%"; //"450px";

        //link=repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    //player to cut files for admin
    public static string getLayerToCutFiles(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;
        string width = "100%";// "600px";
        height = "100%"; //"450px";

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/admin/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/admin/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    //player for admin
    public static string getLayerNotAuto(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;
        string width = "600px";
        height = "450px";

        link = link.Replace(" ~ ", "~");
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/admin/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=false'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/admin/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    //player split for admin
    public static string getLayerNotAutoSplit(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;
        string width = "600px";
        height = "450px";

        link = link.Replace(" ~ ", "~");
        link = comm.repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/admin/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=3&autoStart=false'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src=\"/admin/Viewer/playerCutFileOffline.swf?file=" + link.Replace("%7E", "~") + "&bufferTime=3&autoStart=true\" "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    public static string getLayer(string link, string height)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;

        string width = "100%";
        height = "100%";

        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
            //+ "  value='player.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + "  value='/Control/Viewer/playerCutFileOnline.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + "  value='player.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <embed src='/Control/Viewer/playerCutFileOnline.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    public static string getLayerMultiPOffline(string link)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;

        string width = "100%";
        string height = "100%";

        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/control/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=10&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/control/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=10&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    //string _file,
    //string _duration,
    //string sizeLoad,
    //string urlFile,
    //string urlTimeFile,
    //string urlSizeFile
    public static string getLayerMultiPOffline(string[] infor)
    {
        string _file = infor[0];
        string _duration = infor[1];
        string sizeLoad = infor[2];
        string urlFile = repute(infor[3]);
        string urlTimeFile = repute(infor[4]);
        string urlSizeFile = repute(infor[5]);

        //_file
        string link = _file;
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;
        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string width = "100%";
        string height = "100%";

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " > "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/playerCutFileOffline.swf?file=" + link + "&_duration=" + _duration + "&sizeLoad=" + sizeLoad + "&urlFile=" + urlFile + "&urlTimeFile=" + urlTimeFile + "&sizeFile=" + urlSizeFile + "&bufferTime=10&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/Control/Viewer/playerCutFileOffline.swf?file=" + link + "&_duration=" + _duration + "&sizeLoad=" + sizeLoad + "&urlFile=" + urlFile + "&urlTimeFile=" + urlTimeFile + "&sizeFile=" + urlSizeFile + "&bufferTime=10&autoStart=true' allowfullscreen='true' "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    // version new, can tour
    public static string getLayerMultiPOffline(string link, string _duration, string sizeLoad, string urlFile, string urlTimeFile, string urlSizeFile)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;

        string width = "100%";
        string height = "100%";

        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/playerCutFileOffline.swf?file=" + link + "&_duration=" + _duration + "&sizeLoad=" + sizeLoad + "&urlFile=" + urlFile + "&urlTimeFile=" + urlTimeFile + "&urlSizeFile=" + urlSizeFile + "&bufferTime=10&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/Control/Viewer/playerCutFileOffline.swf?file=" + link + "&_duration=" + _duration + "&sizeLoad=" + sizeLoad + "&urlFile=" + urlFile + "&urlTimeFile=" + urlTimeFile + "&urlSizeFile=" + urlSizeFile + "&bufferTime=10&autoStart=true' allowfullscreen='true' "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    public static string getPlayerKaraoke(string link, string _duration, string filesave, string filekara)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        filekara = sSite + filekara;

        string width = "100%";
        string height = "100%";

        ////link = link.Replace(" ~ ", "~");
        ////link = repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/karaoke.swf?serviceUrl=" + link + "&filekara=" + filekara + "&filesave=" + filesave + "'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/Control/Viewer/karaoke.swf?serviceUrl=" + link + "&filekara=" + filekara + "&filesave=" + filesave + "' allowfullscreen='true' "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    public static string getLayerVoiceMessage(string width, string height, string filesave)
    {

        if (width == "") width = "100%";
        if (height == "") height = "100%";
        string link = comm.GetUrlRecord();
        ////link = link.Replace(" ~ ", "~");
        ////link = repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/VoiceMessage.swf?serviceUrl=" + link + "&filesave=" + filesave + "'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/Control/Viewer/VoiceMessage.swf?serviceUrl=" + link + "&filesave=" + filesave + "' allowfullscreen='true' "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' bgcolor='#FFFFFF' />"
                     + "</object>";
        return HTML;
    }
    public static string getPlayerForVoiceMessage(string width, string height, string filesave)
    {

        if (width == "") width = "100%";
        if (height == "") height = "90%";
        string link = comm.GetUrlRecord();
        ////link = link.Replace(" ~ ", "~");
        ////link = repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/PlayVoiceMessage.swf?serviceUrl=" + link + "&filesave=" + filesave + "'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/Control/Viewer/PlayVoiceMessage.swf?serviceUrl=" + link + "&filesave=" + filesave + "'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' bgcolor='#FFFFFF' allowfullscreen='true' />"
                     + "</object>";
        return HTML;
    }
    // control for smart media
    public static string getLayerPreload(string files)
    {

        string width = "200px";
        string height = "5px";

        string link = comm.GetUrlVideo();

        link = repute(link);

        files = repute(files);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/preLoadFiles.swf.swf?file=" + link + "&urlFile=" + files + "'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/Viewer/preLoadFiles.swf.swf?file=" + link + "&urlFile=" + files + "' "
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' bgcolor='#FFFFFF' />"
                     + "</object>";
        return HTML;
    }
    // get player by id of program
    //player to cut files for admin
    public static string getLayerUser(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideoUser();
        link = sSite + link;
        string width = "100%";// "600px";
        height = "100%"; //"450px";

        //link=repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/Viewer/playerNew.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' bgcolor='#FFFFFF' />"
                     + "</object>";
        return HTML;
    }
    // get player by id of program
    //player to cut files for admin
    public static string getLayerUserShared(string link, string height, string auto)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideoUser();
        link = sSite + link;
        string width = "100%";// "600px";
        height = "100%"; //"450px";

        //link=repute(link);
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/playerEnable.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/Viewer/playerEnable.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' bgcolor='#FFFFFF' />"
                     + "</object>";
        return HTML;
    }
    public static string GetUploadVideoPath()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["uploadVideoFile"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetConvertVideoPath()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["uploadVideoFile"] + "/WMV");
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlSite()
    {
        try
        {
            return ((ConfigurationSettings.AppSettings["sitename"]));
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlRoot()
    {
        try
        {
            return ((ConfigurationSettings.AppSettings["urlRoot"]));
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlOnline()
    {
        try
        {
            return ((ConfigurationSettings.AppSettings["urlOnline"]));
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlBroadCast()
    {
        try
        {
            return ((ConfigurationSettings.AppSettings["urlBroadCast"]));
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlRecord()
    {
        try
        {
            return ((ConfigurationSettings.AppSettings["urlRecord"]));
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUrlVideo()
    {
        string rel = "";
        try
        {
            int i = 1;
            while (true)
            {
                if ((ConfigurationSettings.AppSettings["urlRoot" + i.ToString()]) != null)
                {
                    if (i == 1) rel = (ConfigurationSettings.AppSettings["urlRoot" + i.ToString()]);
                    else rel = rel + "~" + (ConfigurationSettings.AppSettings["urlRoot" + i.ToString()]);
                    i++;
                }
                else break;
            }

        }
        catch (Exception ex) { return ""; }
        return rel;
    }
    public static string GetUploadImagePath()
    {
        try
        {
            string sPath = (ConfigurationSettings.AppSettings["uploadImageFile"]);
            if (!string.IsNullOrEmpty(sPath)) return sPath;
            return "/upload/images/";
        }
        catch (Exception ex) { return "/upload/images/"; }
    }
    public static string GetUploadVideoTempUser()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["uploadVideoFileTempUser"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUploadVideoUser()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["uploadVideoFileUser"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetUploadVideoTemp()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["uploadVideoFileTemp"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetPathPlayVideo()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["pathPlayVideoFile"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string GetPathPlayVideoUser()
    {
        try
        {
            return (ConfigurationSettings.AppSettings["pathPlayVideoFileUser"]);
        }
        catch (Exception ex) { return ""; }
    }
    public static string getFileToLay(string slink)
    {
        try
        {
            return GetPathPlayVideo() + slink;
        }
        catch (Exception ex) { return ""; }
    }
    //image to upload
    public static string GetUrlImage()
    {
        try
        {
            return comm.GetUploadImagePath();
        }
        catch (Exception ex) { return ""; }
    }
    //Time span
    public static TimeSpan GetTimeSpanFromStr(string tm)
    {
        string[] arr = tm.Split(new string[] { ":" }, StringSplitOptions.None);
        return new TimeSpan(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
    }
    //Time span
    public static TimeSpan GetTimeSpanFromMilis(string tm)
    {
        return TimeSpan.FromMilliseconds(double.Parse(tm));
        //string[] arr = tm.Split(new string[] { ":" }, StringSplitOptions.None);
        //return new TimeSpan(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
    }
    //Time span
    public DataTable addSTTToTable(DataTable dt, int pos)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i][pos] = (i + 1);
        }
        return dt;
    }
    //Time span
    public static DataTable Join2Tables(DataTable dt1, DataTable dt2)
    {
        for (int i = 0; i < dt2.Rows.Count; i++)
        {
            DataRow dtR = dt1.NewRow();
            dtR.ItemArray = dt2.Rows[i].ItemArray;
            dt1.Rows.Add(dtR);
        }
        dt1.AcceptChanges();
        return dt1;
    }
    // ma hoa
    public static string repute(string inputString)
    {
        string rel = "";
        for (int i = inputString.Length - 1; i >= 0; i--) rel = rel + inputString.Substring(i, 1);
        return rel;
    }
    public static string getLinkFavor(string ID)
    {
        return "<a href=\"javascript: void(0)\" onclick=\"openWindow('/page/AddFavor.aspx?act=favor&edit=1&ID=" + ID + "','Add Favor',500,250,300,300);return false;\"><img src='/images/green_arrows.gif' />Kênh yêu thích</a>";
    }
    public static void checkLogin()
    {
        //if (comm.GetMemberID() < 0)
        //{
        //    HttpContext.Current.Response.Write("<Script LANGUAGE='JavaScript'>top.location.replace(\"../Default.aspx?show=log\");</script>");
        //}  
    }
    public static bool validateEmail(string sMail)
    {
        if (sMail.Length == 0) return false;
        string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
        System.Text.RegularExpressions.Match match = Regex.Match(sMail.Trim(), pattern, RegexOptions.IgnoreCase);
        return match.Success;
    }
    public static bool validateUsername(string sUserName)
    {
        string[] arrSkip = new string[] { " ", "-", "" };
        return sUserName.IndexOf(" ") == -1;
    }
    public static string getFormat2Digit(string number)
    {
        if (number.Length == 2) return number;
        else return "0" + number;
    }
    //broadcast webcam   
    //player broadcast webcam   
    public static string getPLayerBroadCast(string idBorad, string height, string auto)
    {
        string sService = comm.GetUrlOnline();
        string width = "100%";
        height = "100%";
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/BroadCast.swf?serviceUrl=" + sService + "&iduser=" + idBorad + "'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/Viewer/BroadCast.swf?serviceUrl=" + sService + "&iduser=" + idBorad + "'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    //broadcast webcam   
    //player broadcast webcam   
    public static string getViewPLayerBroadCast(string idBorad, string height, string auto)
    {
        string sService = comm.GetUrlOnline();
        string width = "100%";
        height = "100%";
        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/Control/Viewer/BroadCastViewer.swf?serviceUrl=" + sService + "&iduser=" + idBorad + "'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + " <embed src='/Control/Viewer/BroadCastViewer.swf?serviceUrl=" + sService + "&iduser=" + idBorad + "'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }

    //end broadcast webcam

    #region PLAYER FOR ADMIN
    public static string getLayerMultiPOffline_admin(string link)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;

        string width = "100%";
        string height = "100%";

        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/admin/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=10&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' /> "
                     + " <embed src='/admin/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=10&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }
    public static string getLayer_admin(string link, string height)
    {
        string sSite = GetUrlRoot() + GetPathPlayVideo();
        link = sSite + link;

        string width = "100%";
        height = "100%";

        link = link.Replace(" ~ ", "~");
        link = repute(link);

        string HTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
                     + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'"
                     + " width='" + width + "' height='" + height + "'"
                     + " bgcolor='#FFFFFF'> "
                     + "<param name='movie' "
                     + "  value='/admin/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <param name='quality'"
                     + "   value='high' />"
                     + "  value='player.swf?file=" + link + "&bufferTime=3&autoStart=true'  />"
                     + " <embed src='/admin/Viewer/playerCutFileOffline.swf?file=" + link + "&bufferTime=3&autoStart=true'"
                     + "  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"
                     + " type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' allowFullScreen='true' />"
                     + "</object>";
        return HTML;
    }

    #endregion

    public static string getValLanguage()
    {
        return "";
    }

    public static string getCondLanguage(string p)
    {
        return "1=1";
    }

    public static object getLanguage(string p, string p_2)
    {
        return p;
    }

    public static string GetCurrentYear()
    {
        return DateTime.Now.ToString("yyyy");
    }

    public static string GetCurrentMonth()
    {
        return DateTime.Now.ToString("MM");

    }
    public static int isName(string sInput)
    {
        //return -1;
        string UserChar = "zxcvbnmasdfghjklqwertyuiop1234567890 áàảãạấầẩẫậắằẳẵặéèẻẽẹếềểễệíìỉĩịóòỏõọốồổỗộớờởỡợúùủũụứừửữựýỳỷỹỵâăêôơưđ";
        int idx = -1;
        for (int i = 0; i < sInput.Length; i++)
        {
            idx = UserChar.IndexOf(sInput.ToLower().Substring(i, 1));
            if (idx == -1)
            {
                return i;
            }
        }
        return -1;
    }
    public static int isUserName(string sInput)
    {
        string UserChar = "zxcvbnmasdfghjklqwertyuiop1234567890_@.";
        int idx = -1;
        for (int i = 0; i < sInput.Length; i++)
        {
            idx = UserChar.IndexOf(sInput.ToLower().Substring(i, 1));
            if (idx == -1)
            {
                return i;
            }
        }
        return -1;
    }

    public static string GetCurrentDay()
    {
        return DateTime.Now.Day.ToString();
    }

    public static string GetCurrentHour()
    {
        return DateTime.Now.Hour.ToString();
    }

    public static string GetCurrentMinute()
    {
        return DateTime.Now.Minute.ToString();
    }

    public static string getPathRoot()
    {
        return HttpContext.Current.Server.MapPath("/");
    }

    public static string getDomainName()
    {
        return "mangxahoi.m4me.vn";
    }
    public static string GetImgPath(string imgPath)
    {
        return imgPath;
    }
    public static string xuongdong(int limit, string s)
    {
        string result = "";
        string laststring = s;
        while (laststring.Length > limit)
        {

            string strSub = "";
            strSub = laststring.Substring(0, limit);
            int index = strSub.IndexOf(" ");
            if (index != -1) result += strSub.Substring(0, index);
            else { index = limit; result += strSub; }
            result += "<br>";
            //result +=
            laststring = laststring.Substring(index);
        }
        result += laststring;
        return result;
    }
    /// <summary>
    /// Cắt chuỗi và cộng thêm dấu ... nếu cần
    /// </summary>
    /// <param name="limit"></param>
    /// <param name="s"></param>
    /// <param name="congbacham"></param>
    /// <returns></returns>

    public static string getLimitString(int limit, string s, bool congbacham)
    {

        if (s.Length > limit)
        {
            try
            {
                if (congbacham)
                {
                    if (limit > 3) limit = limit - 3;
                    s = s.Substring(0, limit);
                    if (s.IndexOf(" ") != -1) s = s.Substring(0, s.LastIndexOf(" "));
                    s = s + "...";
                }

                else s = s.Substring(0, limit);
            }
            catch { s = s.Substring(0, limit); }
        }

        return s;
    }
    public static string TrimVietnameseMark(string str)
    {
        str = str.Replace(".", " ");
        str = str.Replace(",", " ");
        str = str.Replace("_", " ");
        str = str.Replace(";", " ");
        str = str.Replace("?", " ");
        str = str.Replace("(", "");
        str = str.Replace(")", "");
        str = str.Replace("[", "");
        str = str.Replace("]", "");
        str = str.Replace("{", "");
        str = str.Replace("}", "");
        str = str.Replace("<", "");
        str = str.Replace(">", "");
        str = str.Replace("'", "");

        while (str.IndexOf("  ") > 0)
        {
            str = str.Replace("  ", " ");
        }

        str = str.Replace("ấ", "a");
        str = str.Replace("ầ", "a");
        str = str.Replace("ẩ", "a");
        str = str.Replace("ẫ", "a");
        str = str.Replace("ậ", "a");

        str = str.Replace("Ấ", "A");
        str = str.Replace("Ầ", "A");
        str = str.Replace("Ẩ", "A");
        str = str.Replace("Ẫ", "A");
        str = str.Replace("Ậ", "A");

        str = str.Replace("ắ", "a");
        str = str.Replace("ằ", "a");
        str = str.Replace("ẳ", "a");
        str = str.Replace("ẵ", "a");
        str = str.Replace("ặ", "a");

        str = str.Replace("Ắ", "A");
        str = str.Replace("Ằ", "A");
        str = str.Replace("Ẳ", "A");
        str = str.Replace("Ẵ", "A");
        str = str.Replace("Ặ", "A");

        str = str.Replace("á", "a");
        str = str.Replace("à", "a");
        str = str.Replace("ả", "a");
        str = str.Replace("ã", "a");
        str = str.Replace("ạ", "a");
        str = str.Replace("â", "a");
        str = str.Replace("ă", "a");

        str = str.Replace("Á", "A");
        str = str.Replace("À", "A");
        str = str.Replace("Ả", "A");
        str = str.Replace("Ã", "A");
        str = str.Replace("Ạ", "A");
        str = str.Replace("Â", "A");
        str = str.Replace("Ă", "A");

        str = str.Replace("ế", "e");
        str = str.Replace("ề", "e");
        str = str.Replace("ể", "e");
        str = str.Replace("ễ", "e");
        str = str.Replace("ệ", "e");

        str = str.Replace("Ế", "E");
        str = str.Replace("Ề", "E");
        str = str.Replace("Ể", "E");
        str = str.Replace("Ễ", "E");
        str = str.Replace("Ệ", "E");

        str = str.Replace("é", "e");
        str = str.Replace("è", "e");
        str = str.Replace("ẻ", "e");
        str = str.Replace("ẽ", "e");
        str = str.Replace("ẹ", "e");
        str = str.Replace("ê", "e");

        str = str.Replace("É", "E");
        str = str.Replace("È", "E");
        str = str.Replace("Ẻ", "E");
        str = str.Replace("Ẽ", "E");
        str = str.Replace("Ẹ", "E");
        str = str.Replace("Ê", "E");

        str = str.Replace("í", "i");
        str = str.Replace("ì", "i");
        str = str.Replace("ỉ", "i");
        str = str.Replace("ĩ", "i");
        str = str.Replace("ị", "i");

        str = str.Replace("Í", "I");
        str = str.Replace("Ì", "I");
        str = str.Replace("Ỉ", "I");
        str = str.Replace("Ĩ", "I");
        str = str.Replace("Ị", "I");

        str = str.Replace("ố", "o");
        str = str.Replace("ồ", "o");
        str = str.Replace("ổ", "o");
        str = str.Replace("ỗ", "o");
        str = str.Replace("ộ", "o");

        str = str.Replace("Ố", "O");
        str = str.Replace("Ồ", "O");
        str = str.Replace("Ổ", "O");
        str = str.Replace("Ô", "O");
        str = str.Replace("Ộ", "O");

        str = str.Replace("ớ", "o");
        str = str.Replace("ờ", "o");
        str = str.Replace("ở", "o");
        str = str.Replace("ỡ", "o");
        str = str.Replace("ợ", "o");

        str = str.Replace("Ớ", "O");
        str = str.Replace("Ờ", "O");
        str = str.Replace("Ở", "O");
        str = str.Replace("Ỡ", "O");
        str = str.Replace("Ợ", "O");

        str = str.Replace("ứ", "u");
        str = str.Replace("ừ", "u");
        str = str.Replace("ử", "u");
        str = str.Replace("ữ", "u");
        str = str.Replace("ự", "u");

        str = str.Replace("Ứ", "U");
        str = str.Replace("Ừ", "U");
        str = str.Replace("Ử", "U");
        str = str.Replace("Ữ", "U");
        str = str.Replace("Ự", "U");

        str = str.Replace("ý", "y");
        str = str.Replace("ỳ", "y");
        str = str.Replace("ỷ", "y");
        str = str.Replace("ỹ", "y");
        str = str.Replace("ỵ", "y");

        str = str.Replace("Ý", "Y");
        str = str.Replace("Ỳ", "Y");
        str = str.Replace("Ỷ", "Y");
        str = str.Replace("Ỹ", "Y");
        str = str.Replace("Ỵ", "Y");

        str = str.Replace("Đ", "D");
        str = str.Replace("Đ", "D");
        str = str.Replace("đ", "d");

        str = str.Replace("ó", "o");
        str = str.Replace("ò", "o");
        str = str.Replace("ỏ", "o");
        str = str.Replace("õ", "o");
        str = str.Replace("ọ", "o");
        str = str.Replace("ô", "o");
        str = str.Replace("ơ", "o");

        str = str.Replace("Ó", "O");
        str = str.Replace("Ò", "O");
        str = str.Replace("Ỏ", "O");
        str = str.Replace("Õ", "O");
        str = str.Replace("Ọ", "O");
        str = str.Replace("Ô", "O");
        str = str.Replace("Ơ", "O");

        str = str.Replace("ú", "u");
        str = str.Replace("ù", "u");
        str = str.Replace("ủ", "u");
        str = str.Replace("ũ", "u");
        str = str.Replace("ụ", "u");
        str = str.Replace("ư", "u");

        str = str.Replace("Ú", "U");
        str = str.Replace("Ù", "U");
        str = str.Replace("Ủ", "U");
        str = str.Replace("Ũ", "U");
        str = str.Replace("Ụ", "U");
        str = str.Replace("Ư", "U");

        str = str.ToLower();

        return str;
    }
    public static string TrimVietnameseMark(string str, bool isLower)
    {
        str = str.Replace(".", " ");
        str = str.Replace(",", " ");
        str = str.Replace("_", " ");
        str = str.Replace(";", " ");
        str = str.Replace("?", " ");
        str = str.Replace("(", "");
        str = str.Replace(")", "");
        str = str.Replace("[", "");
        str = str.Replace("]", "");
        str = str.Replace("{", "");
        str = str.Replace("}", "");
        str = str.Replace("<", "");
        str = str.Replace(">", "");
        str = str.Replace("'", "");

        while (str.IndexOf("  ") > 0)
        {
            str = str.Replace("  ", " ");
        }

        str = str.Replace("ấ", "a");
        str = str.Replace("ầ", "a");
        str = str.Replace("ẩ", "a");
        str = str.Replace("ẫ", "a");
        str = str.Replace("ậ", "a");

        str = str.Replace("Ấ", "A");
        str = str.Replace("Ầ", "A");
        str = str.Replace("Ẩ", "A");
        str = str.Replace("Ẫ", "A");
        str = str.Replace("Ậ", "A");

        str = str.Replace("ắ", "a");
        str = str.Replace("ằ", "a");
        str = str.Replace("ẳ", "a");
        str = str.Replace("ẵ", "a");
        str = str.Replace("ặ", "a");

        str = str.Replace("Ắ", "A");
        str = str.Replace("Ằ", "A");
        str = str.Replace("Ẳ", "A");
        str = str.Replace("Ẵ", "A");
        str = str.Replace("Ặ", "A");

        str = str.Replace("á", "a");
        str = str.Replace("à", "a");
        str = str.Replace("ả", "a");
        str = str.Replace("ã", "a");
        str = str.Replace("ạ", "a");
        str = str.Replace("â", "a");
        str = str.Replace("ă", "a");

        str = str.Replace("Á", "A");
        str = str.Replace("À", "A");
        str = str.Replace("Ả", "A");
        str = str.Replace("Ã", "A");
        str = str.Replace("Ạ", "A");
        str = str.Replace("Â", "A");
        str = str.Replace("Ă", "A");

        str = str.Replace("ế", "e");
        str = str.Replace("ề", "e");
        str = str.Replace("ể", "e");
        str = str.Replace("ễ", "e");
        str = str.Replace("ệ", "e");

        str = str.Replace("Ế", "E");
        str = str.Replace("Ề", "E");
        str = str.Replace("Ể", "E");
        str = str.Replace("Ễ", "E");
        str = str.Replace("Ệ", "E");

        str = str.Replace("é", "e");
        str = str.Replace("è", "e");
        str = str.Replace("ẻ", "e");
        str = str.Replace("ẽ", "e");
        str = str.Replace("ẹ", "e");
        str = str.Replace("ê", "e");

        str = str.Replace("É", "E");
        str = str.Replace("È", "E");
        str = str.Replace("Ẻ", "E");
        str = str.Replace("Ẽ", "E");
        str = str.Replace("Ẹ", "E");
        str = str.Replace("Ê", "E");

        str = str.Replace("í", "i");
        str = str.Replace("ì", "i");
        str = str.Replace("ỉ", "i");
        str = str.Replace("ĩ", "i");
        str = str.Replace("ị", "i");

        str = str.Replace("Í", "I");
        str = str.Replace("Ì", "I");
        str = str.Replace("Ỉ", "I");
        str = str.Replace("Ĩ", "I");
        str = str.Replace("Ị", "I");

        str = str.Replace("ố", "o");
        str = str.Replace("ồ", "o");
        str = str.Replace("ổ", "o");
        str = str.Replace("ỗ", "o");
        str = str.Replace("ộ", "o");

        str = str.Replace("Ố", "O");
        str = str.Replace("Ồ", "O");
        str = str.Replace("Ổ", "O");
        str = str.Replace("Ô", "O");
        str = str.Replace("Ộ", "O");

        str = str.Replace("ớ", "o");
        str = str.Replace("ờ", "o");
        str = str.Replace("ở", "o");
        str = str.Replace("ỡ", "o");
        str = str.Replace("ợ", "o");

        str = str.Replace("Ớ", "O");
        str = str.Replace("Ờ", "O");
        str = str.Replace("Ở", "O");
        str = str.Replace("Ỡ", "O");
        str = str.Replace("Ợ", "O");

        str = str.Replace("ứ", "u");
        str = str.Replace("ừ", "u");
        str = str.Replace("ử", "u");
        str = str.Replace("ữ", "u");
        str = str.Replace("ự", "u");

        str = str.Replace("Ứ", "U");
        str = str.Replace("Ừ", "U");
        str = str.Replace("Ử", "U");
        str = str.Replace("Ữ", "U");
        str = str.Replace("Ự", "U");

        str = str.Replace("ý", "y");
        str = str.Replace("ỳ", "y");
        str = str.Replace("ỷ", "y");
        str = str.Replace("ỹ", "y");
        str = str.Replace("ỵ", "y");

        str = str.Replace("Ý", "Y");
        str = str.Replace("Ỳ", "Y");
        str = str.Replace("Ỷ", "Y");
        str = str.Replace("Ỹ", "Y");
        str = str.Replace("Ỵ", "Y");

        str = str.Replace("Đ", "D");
        str = str.Replace("Đ", "D");
        str = str.Replace("đ", "d");

        str = str.Replace("ó", "o");
        str = str.Replace("ò", "o");
        str = str.Replace("ỏ", "o");
        str = str.Replace("õ", "o");
        str = str.Replace("ọ", "o");
        str = str.Replace("ô", "o");
        str = str.Replace("ơ", "o");

        str = str.Replace("Ó", "O");
        str = str.Replace("Ò", "O");
        str = str.Replace("Ỏ", "O");
        str = str.Replace("Õ", "O");
        str = str.Replace("Ọ", "O");
        str = str.Replace("Ô", "O");
        str = str.Replace("Ơ", "O");

        str = str.Replace("ú", "u");
        str = str.Replace("ù", "u");
        str = str.Replace("ủ", "u");
        str = str.Replace("ũ", "u");
        str = str.Replace("ụ", "u");
        str = str.Replace("ư", "u");

        str = str.Replace("Ú", "U");
        str = str.Replace("Ù", "U");
        str = str.Replace("Ủ", "U");
        str = str.Replace("Ũ", "U");
        str = str.Replace("Ụ", "U");
        str = str.Replace("Ư", "U");

        if (isLower) str = str.ToLower();

        return str;
    }
    public static string TrimSpecialChar(string str)
    {
        str = TrimVietnameseMark(str);
        str = str.Replace(".", " ");
        str = str.Replace(",", " ");
        str = str.Replace("_", " ");
        str = str.Replace(";", " ");
        str = str.Replace("?", " ");
        str = str.Replace("(", "");
        str = str.Replace(")", "");
        str = str.Replace("[", "");
        str = str.Replace("]", "");
        str = str.Replace("{", "");
        str = str.Replace("}", "");
        str = str.Replace("<", "");
        str = str.Replace(">", "");
        str = str.Replace("'", "");
        //
        str = str.Replace("`", "");
        str = str.Replace("&", "");
        str = str.Replace("^", "");
        str = str.Replace("$", "");
        str = str.Replace("%", "");
        str = str.Replace("#", "");
        str = str.Replace("@", "");
        str = str.Replace("*", "");
        str = str.Replace("-", "");
        while (str.IndexOf("  ") > 0)
        {
            str = str.Replace("  ", " ");
        }
        return str;
    }
    /// <summary>
    /// Nếu là trang để test thì return "block"
    /// không thì return "none"
    /// </summary>
    /// <returns></returns>
    public static string isTestPage(string domain)
    {
        return "block";
        if (domain.ToLower().Contains("test.m4me.vn")) return "block";
        return "none";
    }
    public static string getHiddenTel(string tel)
    {
        if (tel.StartsWith("+84")) tel = tel.Substring(0, 5) + "**" + tel.Substring(7, tel.Length - 7);
        return tel;
    }
    /// <summary>
    /// Chuyển từ số dang định dạng tiền tệ (VND)
    /// </summary>
    /// <param name="number"></param>
    /// <returns></returns>
    public static string numberToCurrency(int number)
    {
        NumberFormatInfo nfi;
        nfi = new NumberFormatInfo();
        nfi.CurrencySymbol = "VND ";
        string sString = string.Format(nfi, "{0:C}", number);
        if (number < 0) sString = "- " + sString;

        return sString;
    }
    /// <summary>
    /// Chuyển từ số dang định dạng tiền tệ (VND)
    /// </summary>
    /// <param name="number"></param>
    /// <returns></returns>
    public static string numberToCurrency(long number)
    {
        NumberFormatInfo nfi;
        nfi = new NumberFormatInfo();
        nfi.CurrencySymbol = "VND ";
        string sString = string.Format(nfi, "{0:C}", number);
        if (number < 0) sString = "- " + sString;

        return sString;
    }
    public static string numberToCurrency(string sNumber)
    {
        int number = int.Parse(sNumber);
        NumberFormatInfo nfi;
        nfi = new NumberFormatInfo();
        nfi.CurrencySymbol = "";
        string sString = string.Format(nfi, "{0:C0}", number);
        if (number < 0) sString = "- " + sString;

        return sString;
    }
    public static bool isMobileBrowser()
    {
        //GETS THE CURRENT USER CONTEXT
        HttpContext context = HttpContext.Current;

        //FIRST TRY BUILT IN ASP.NT CHECK
        if (context.Request.Browser.IsMobileDevice)
        {
            return true;
        }
        //THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
        if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
        {
            return true;
        }
        //THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
        if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
            context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
        {
            return true;
        }
        //AND FINALLY CHECK THE HTTP_USER_AGENT 
        //HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
        if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
        {
            //Create a list of all mobile types
            string[] mobiles =
                new[]
                {
                    "midp", "j2me", "avant", "docomo", 
                    "novarra", "palmos", "palmsource", 
                    "240x320", "opwv", "chtml",
                    "pda", "windows ce", "mmp/", 
                    "blackberry", "mib/", "symbian", 
                    "wireless", "nokia", "hand", "mobi",
                    "phone", "cdm", "up.b", "audio", 
                    "SIE-", "SEC-", "samsung", "HTC", 
                    "mot-", "mitsu", "sagem", "sony"
                    , "alcatel", "lg", "eric", "vx", 
                    "NEC", "philips", "mmm", "xx", 
                    "panasonic", "sharp", "wap", "sch",
                    "rover", "pocket", "benq", "java", 
                    "pt", "pg", "vox", "amoi", 
                    "bird", "compal", "kg", "voda",
                    "sany", "kdd", "dbt", "sendo", 
                    "sgh", "gradi", "jb", "dddi", 
                    "moto", "iphone"
                };

            //Loop through each item in the list created above 
            //and check if the header contains that text
            foreach (string s in mobiles)
            {
                if (context.Request.ServerVariables["HTTP_USER_AGENT"].
                                                    ToLower().Contains(s.ToLower()))
                {
                    return true;
                }
            }
        }

        return false;
    }


}
